import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TAcupointConfig } from "../../../Message/Db/Tables/TAcupointConfig";
import { StringHelper } from "../../../com/gengine/utils/StringHelper";
import { JSON } from "../../../com/mui/serialization/json/JSON";
import { BournInfo } from "../model/BournInfo";
import { AcupointIntroInfo } from "../model/AcupointIntroInfo";
import { RootBreakThroughInfo } from "../model/RootBreakThroughInfo";
import { TRootTargetConfig } from "../../../Message/Db/Tables/TRootTargetConfig";
import { CareerUtil } from "../view/common/util/CareerUtil";
type int = number;
//class AcupointConfig
    
    export  class AcupointConfig
    {
        constructor()
        {
            
            this._acupointUpgradeMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._rootUpgradeMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._savvyUpgradeMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._bournMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._acupointIntroMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._bournArr = [];
            this._rootBreakThroughMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._rootTargetMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._rootTargetArr = [];
            this._savvyUpgradeCostMap = new Map<any, any> /* flash.utils.Dictionary */();
            if (AcupointConfig._instance != null) 
            {
                throw new Error("AcupointConfig单例");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_acupoint_config.json");
            this.write(loc1);
            var loc2=ConfigManager.instance.getJSONByFileName("t_root_target_config.json");
            this.writeRootTarget(loc2);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=0;
            var loc8=arg1;
            label690: for(loc6 of loc8) 
            {
                loc1 = new TAcupointConfig();
                loc1.addper = loc6.addper;
                loc1.cost = loc6.cost;
                loc1.id = loc6.id;
                loc1.jsStr = StringHelper.getString(loc6.jsStr);
                loc1.nimbus = loc6.nimbus;
                loc1.num = loc6.num;
                loc1.oper = StringHelper.getString(loc6.oper);
                loc1.rate = loc6.rate;
                loc1.step = loc6.step;
                loc1.level = loc6.level;
                loc1.time = loc6.time;
                loc1.unit = loc6.unit;
                var loc9=loc6.oper;
                switch (loc9) 
                {
                    case "AcupointUpgrade":
                    {
                        this._acupointUpgradeMap[loc1.level + "_" + loc1.step] = loc1;
                        continue label690;
                    }
                    case "RootUpgrade":
                    {
                        this._rootUpgradeMap[loc1.level] = loc1;
                        continue label690;
                    }
                    case "SavvyUpgrade":
                    {
                        this._savvyUpgradeMap[loc1.level] = loc1;
                        continue label690;
                    }
                    case "BournConfig":
                    {
                        loc2 = JSON.deserialize(loc6.jsStr);
                        (loc3 = new BournInfo()).acupointLevel = loc1.level;
                        loc3.name = loc2.name;
                        loc3.info = loc2.info;
                        this._bournMap[loc3.acupointLevel] = loc3;
                        this._bournArr.push(loc3.acupointLevel);
                        continue label690;
                    }
                    case "AcupointConfig":
                    {
                        loc2 = JSON.deserialize(loc6.jsStr);
                        (loc4 = new AcupointIntroInfo()).step = loc1.step;
                        loc4.info = StringHelper.getString(loc2.info);
                        this._acupointIntroMap[loc4.step] = loc4;
                        continue label690;
                    }
                    case "RootBreakThrough":
                    {
                        loc2 = JSON.deserialize(loc6.jsStr);
                        (loc5 = new RootBreakThroughInfo()).maxRoot = loc2.maxRoot;
                        loc5.tAcupointConfig = loc1;
                        this._rootBreakThroughMap[loc1.level] = loc5;
                        continue label690;
                    }
                    case "SavvyUpgradeCost":
                    {
                        this._savvyUpgradeCostMap[loc1.level] = loc1;
                        continue label690;
                    }
                }
            }
            this._bournArr.sortOn("", Array.NUMERIC);
            return;
        }

        /* internal  */writeRootTarget(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TRootTargetConfig();
                loc1.attack = loc2.attack;
                loc1.career = loc2.career;
                loc1.crit = loc2.crit;
                loc1.descStr = loc2.descStr;
                loc1.level = loc2.level;
                loc1.life = loc2.life;
                loc1.toughness = loc2.toughness;
                this._rootTargetMap[loc1.career + "_" + loc1.level] = loc1;
                if (loc1.career != 17) 
                {
                    continue;
                }
                this._rootTargetArr.push(loc1.level);
            }
            this._rootTargetArr.sortOn("", Array.NUMERIC);
            return;
        }

        public getAcupointInfo(arg1: int, arg2: int): TAcupointConfig
        {
            return this._acupointUpgradeMap[arg1 + "_" + arg2];
        }

        public getRootInfoByTarget(arg1: int): TAcupointConfig
        {
            return this._rootUpgradeMap[arg1];
        }

        public getSavvyInfoByTarget(arg1: int): TAcupointConfig
        {
            return this._savvyUpgradeMap[arg1];
        }

        public getBournInfoByLevel(arg1: int): BournInfo
        {
            if (arg1 == 0) 
            {
                arg1 = this._bournArr[0];
            }
            return this._bournMap[arg1];
        }

        public getNextBournInfoByLevel(arg1: int): BournInfo
        {
            var loc2=0;
            var loc1=this.getBournIndex(arg1);
            if (this._bournArr[loc1]) 
            {
                loc2 = this._bournArr[loc1];
            }
            return this._bournMap[loc2];
        }

        public getAcuIntroInfoByStep(arg1: int): string
        {
            var loc1=this._acupointIntroMap[arg1];
            return loc1.info;
        }

        public getBournIndex(arg1: int): int
        {
            var loc1=1;
            var loc2=0;
            while (loc2 < this._bournArr.length) 
            {
                if (this._bournArr[loc2] == arg1) 
                {
                    loc1 = loc2 + 1;
                    break;
                }
                ++loc2;
            }
            return loc1;
        }

        public getRootTargetByCareerAndLevel(arg1: int, arg2: int): TRootTargetConfig
        {
            arg1 = CareerUtil.getSumCareer(arg1);
            if (arg2 == 0) 
            {
                arg2 = this._rootTargetArr[0];
            }
            return this._rootTargetMap[arg1 + "_" + arg2];
        }

        public getNextRootTargetByCareerAndLevel(arg1: int, arg2: int): TRootTargetConfig
        {
            arg1 = CareerUtil.getSumCareer(arg1);
            var loc1=this._rootTargetArr.indexOf(arg2);
            var loc2=this._rootTargetArr[loc1 + 1];
            return this._rootTargetMap[arg1 + "_" + loc2];
        }

        public getRootTargetIndex(arg1: int): int
        {
            var loc1=1;
            var loc2=0;
            while (loc2 < this._rootTargetArr.length) 
            {
                if (this._rootTargetArr[loc2] == arg1) 
                {
                    loc1 = loc2 + 1;
                    break;
                }
                ++loc2;
            }
            return loc1;
        }

        public getRootBreakThroughByLevel(arg1: int): RootBreakThroughInfo
        {
            if (arg1 < 100) 
            {
                arg1 = 100;
            }
            var loc1=this._rootBreakThroughMap[arg1];
            return loc1;
        }

        public getSavvyUpgradeCostInfo(arg1: int): TAcupointConfig
        {
            var loc1=arg1 - arg1 % 10;
            loc1 = loc1 + 1;
            return this._savvyUpgradeCostMap[loc1];
        }

        public isCanBreakThrough(arg1: int): Boolean
        {
            var loc2=null;
            var loc1=false;
            var loc3=0;
            var loc4=this._rootBreakThroughMap;
            for(loc2 of loc4) 
            {
                if (loc2.tAcupointConfig.level != arg1) 
                {
                    continue;
                }
                loc1 = true;
                break;
            }
            return loc1;
        }

        public static get instance(): AcupointConfig
        {
            if (AcupointConfig._instance == null) 
            {
                AcupointConfig._instance = new AcupointConfig();
            }
            return AcupointConfig._instance;
        }

        /* internal */ /* var */_acupointUpgradeMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_rootUpgradeMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_savvyUpgradeMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_bournMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_acupointIntroMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_bournArr: Array<any>;

        /* internal */ /* var */_rootBreakThroughMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_rootTargetMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_rootTargetArr: Array<any>;

        /* internal */ /* var */_savvyUpgradeCostMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: AcupointConfig;
    }
